// 封装请求
let host = 'https://api.it120.cc/small4/'

function Request({
  url,
  data = {},
  method
}) {
  wx.showLoading({
    title: '正在加载...',
  })
  // let token = wx.getStorageSync('token');
  // if (token) {
  //   data = {
  //     ...data,
  //     token
  //   }
  // }
  return new Promise((resolve, reject) => {
    wx.request({
      url: host + url,
      method: method,
      data: data,
      // 登录表单的请求头部要求啥就改成啥
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: (res) => {
        resolve(res.data)
      },
      fail: (res) => {
        reject(res.data)
      },
      complete: () => {
        wx.hideLoading()
      }
    })
  })

}
export {
  Request
}